package com.bytz.modules.cms.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bytz.common.api.vo.Result;
import com.bytz.modules.cms.common.constants.AdminAuthConstants;
import com.bytz.modules.cms.order.model.OrderPickUpDetailModel;
import com.bytz.modules.cms.order.service.IAdminOrderPickUpDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@Api(tags = "提货列表")
@RequestMapping("/pickUp")
@PreAuthorize("hasAuthority('" + AdminAuthConstants.OderPickUp.VIEW + "')")
public class OrderPickUpDetailController {

    @Autowired
    private IAdminOrderPickUpDetailService orderPickUpDetailService;

    @ApiOperation(value = "分页查询", notes = "分页查询")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result<IPage<OrderPickUpDetailModel>> page(OrderPickUpDetailModel orderPickUpDetail,
                                                      @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                      HttpServletRequest req) throws Exception {
        return Result.ok(orderPickUpDetailService.queryPage(new Page<>(pageNo, pageSize), orderPickUpDetail, req.getParameterMap()));
    }

    @ApiOperation(value = "提货列表导出", notes = "提货列表导出")
    @RequestMapping(value = "/export", method = RequestMethod.POST)
    public void export(OrderPickUpDetailModel orderPickUpDetail,
                       HttpServletRequest request,
                       HttpServletResponse response) throws Exception {

        orderPickUpDetailService.export(orderPickUpDetail, request.getParameterMap(), response);
    }

}
